package com.baoxin.chenxixc4coach.java;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

import com.baoxin.chenxixc4coach.LoginActivity;
import com.baoxin.chenxixc4coach.utils.Msg;

public class MyHandler extends Handler {
    IActivityLifeCheck iActivityLifeCheck;
    Activity activity;

    public MyHandler(IActivityLifeCheck iActivityLifeCheck, Activity activity) {
        this.iActivityLifeCheck = iActivityLifeCheck;
        this.activity = activity;
    }

    @Override
    public void handleMessage(Message msg) {

        super.handleMessage(msg);
        boolean isAlive = iActivityLifeCheck.activityAlive();
        if (!isAlive) {
            return;
        }
        if (msg.what == -2) {
            Intent intent = new Intent(activity, LoginActivity.class);
            activity.startActivityForResult(intent,1);
        } else if (msg.what == -1 || msg.what == Msg.ONFAILURE) {
            Toast.makeText(activity, msg.getData().getString("msg"), Toast.LENGTH_SHORT).show();
        }


    }
}
